package pro.softzhang.algo.lc2300;

import pro.softzhang.algo.flag.knowledge.KGraph;

import java.util.Arrays;

/**
 *
 */
public class LC2352_EqualRowAndColumnPairs {
    public static void main(String[] args) {
        int[][] grid = {{3, 2, 1}, {1, 7, 6}, {2, 7, 7}};
        System.out.println(new Solution().equalPairs(grid));
    }

    @KGraph
    static
    class Solution {
        public int equalPairs(int[][] grid) {
            int[][] transposed = new int[grid.length][grid[0].length];
            for(int i = 0; i < grid.length; i++) {
                for(int j = 0; j < grid[i].length; j++) {
                    transposed[j][i] = grid[i][j];
                }
            }

            int pairs = 0;
            for(int i = 0; i < grid.length; i++) {
                for(int j = 0; j < transposed.length; j++) {
                    if(Arrays.equals(grid[i], transposed[j])) {
                        pairs++;
                    }
                }
            }
            return pairs;
        }
    }
}
